﻿using System;
using System.Globalization;

namespace WGS84
{
    public class Degrees
    {
        readonly Double _degrees;

        /// <summary>
        /// Angle in degrees
        /// </summary>
        /// <returns>Double precision value</returns>
        public double ToDouble()
        {
            return _degrees;
        }

        /// <summary>
        /// Instance constructor
        /// </summary>
        /// <param name="degrees">Angle in degrees</param>
        public Degrees(double degrees)
        {
            _degrees = degrees;
        }

        /// <summary>
        /// Angle converted to radians
        /// </summary>
        /// <returns>Double precision value</returns>
        public double ToRadians()
        {
            return _degrees * (Math.PI / 180.0);
        }

        /// <summary>
        /// Compares by value two Degrees objects
        /// </summary>
        /// <param name="obj">object for comparison</param>
        /// <returns>Whether they are equal</returns>
        public override bool Equals(object obj)
        {
            if (obj == null) 
                return false;

            if (ReferenceEquals(this, obj)) 
                return true;

            if (GetType() != obj.GetType()) 
                return false;
            var that = (Degrees)obj;

            if (!_degrees.Equals(that._degrees)) 
                return false;

            return true;
        }
        /// <summary>
        /// Calculate Hash code for this object
        /// </summary>
        /// <returns>Hashcode based on member variables</returns>
        public override int GetHashCode()
        {
            int hash = _degrees.GetHashCode();
            return hash;
        }

        /// <summary>
        /// Get legible string
        /// </summary>
        /// <returns>Human readable string</returns>
        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentCulture, "{0} Degrees", _degrees);
        }
    }
}
